package com.cssl.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class MyConverter implements Converter<String, Date> {
	private static final SimpleDateFormat[] sds = new SimpleDateFormat[5];
	static {
		sds[0] = new SimpleDateFormat("dd-MM-yyyy");
		sds[1] = new SimpleDateFormat("yyyy-MM-dd");
		sds[2] = new SimpleDateFormat("yyyy/MM/dd");
		sds[3] = new SimpleDateFormat("yyyy年MM月dd日");
		sds[4] = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	}
	@Override
	public Date convert(String arg0) {

		for (SimpleDateFormat s : sds) {
			try {
				return s.parse(arg0);
			} catch (ParseException e) {
				continue;
			}
		}
		return new Date();
	}
}
